/**
 * Created by mac on 17/7/21.
 */
var api=require("API");
module.exports = ['$scope','$http',function ($scope,$http) {
    var _API = require('_API')($http);

    $(".upload").on("change","input[type='file']",function(){
        var filePath=$(this).val();
        var arr = filePath.split('\\');
        var fileName = arr[arr.length-1];
        console.log(fileName);
        // if(filePath.indexOf("jpg")!=-1 || filePath.indexOf("png")!=-1){
        //     $(".fileerrorTip").html("").hide();
        //     var arr=filePath.split('\\');
        //     var fileName=arr[arr.length-1];
        //     $(".showFileName").html(fileName);
        // }else{
        //     $(".showFileName").html("");
        //     $(".fileerrorTip").html("您未上传文件，或者您上传文件类型有误！").show();
        //     return false
        // }
    })


    $scope.upload_user=function(){
        var user = new FormData(document.getElementById("form_user"));
        $.ajax({
            url:"/api/users/import",
            type:"post",
            data:user,
            processData:false,
            contentType:false,
            success:function(data){
                alert('提交成功！');
            },
            error:function(error){
                alert(error.responseText);
            }
        })
    };

    $scope.upload_vehicle_model=function(){
        console.log('zx');
        var vehicle_model= new FormData(document.getElementById("form_vehicle_model"));

        $.ajax({
            url:"/api/vehicle_model/import",
            type:"post",
            data:vehicle_model,
            processData:false,
            contentType:false,
            success:function(data){
                alert('提交成功！');
            },
            error:function(error){
                alert(error.responseText);
            }
        })
    };

    $scope.upload_visit=function(){
        var visit= new FormData(document.getElementById("form_visit"));
        api.visit.import(visit);
    };
    // $scope.import_salesman=function(){
    //     api.performance.salesman.import_salesman_for_performance(function () {
    //
    //     })
    // }

}];